/*
2021-7-16
https://www.acwing.com/problem/content/1102/
*/
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
const int N=1e5+5;
int n,k;
bool st[N];
int q[N];
int dist[N];

int bfs(int n,int k)
{
    memset(dist,0x3f3f3f3f,sizeof dist);
    int hh=0,tt=0;
    dist[n]=0;
    q[0]=n;
    while(hh<=tt)
    {
        int t=q[hh++];
        if(t-1>=0 && dist[t-1]>dist[t]+1)
        {
            dist[t-1]=dist[t]+1;
            q[++tt]=t-1;
        }
        if(t+1<=N-1 && dist[t+1]>dist[t]+1)
        {
            dist[t+1]=dist[t]+1;
            q[++tt]=t+1;
        }
        if(2*t<=N-1 && dist[2*t]>dist[t]+2)
        {
            dist[2*t]=dist[t]+1;
            q[++tt]=2*t;
        }
        if(dist[k]!=0x3f3f3f3f) return dist[k];
    }
    return dist[k];
}

int main()
{
    cin>>n>>k;
    cout<<bfs(n,k);
    return 0;
}
